package jichengheduotai;

public class Test {
    public static void main(String[] args) {

        //继承版猫咪
        //空参构造创建
        Cat c1 = new Cat();
        c1.setName("1号猫咪");
        c1.setAge(1);
        System.out.println(c1.getName() + "+" + c1.getAge());
        c1.eat(c1.getName());
        System.out.println("--------------");
        //带参构造创建
        Cat c2 = new Cat("2号猫咪", 2);
        System.out.println(c2.getName() + "+" + c2.getAge());
        c2.eat(c2.getName());
        c2.catchMouse(c2.getName());
        System.out.println("--------------");
        //继承中父类可实例化
        Animal a1 = new Animal();
        a1.eat("a1");
        System.out.println("--------------");

        //多态版
        Animal a = new Cat("动物1号猫",3);
        a.eat(a.getName());
        //Animal类强转为Cat类后才能调用Cat类特有方法
        ((Cat) a).catchMouse(a.getName());
        System.out.println("--------------");
        //多态中
        Animal a2 = new Animal();
        a2.eat("a2");

    }
}
